package cn.net.isir.controller.manager;

import cn.net.isir.common.ResultObject;
import cn.net.isir.core.BasicController;
import cn.net.isir.core.SetBasicService;
import cn.net.isir.entity.Medals;
import cn.net.isir.service.MedalsService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author liuxubo
 * @filename MedalsController.java
 * @package cn.net.isir.controller.manager
 * @email lxb@isir.net.cn
 * @date 2019/02/26
 * @comment
 * @since 1.8
 */
@RestController
@RequestMapping("/medal")
public class MedalsController extends BasicController<Medals> {
    @SetBasicService
    @Resource
    private MedalsService medalsService;

    /**
     * 增加信息
     *
     * @param map 增加信息
     * @return 结果
     */
    @Override
    public ResultObject add(@RequestBody Map map) {
        Medals medals = JSONObject.parseObject(JSON.toJSONString(map), Medals.class);
        // 排序
        medalsService.reSort(medals);
        return super.add(map);
    }

    /**
     * 保存修改信息
     *
     * @param map 信息实体类
     * @return 结果
     */
    @Override
    public ResultObject edit(@RequestBody Map map) {
        Medals medals = JSONObject.parseObject(JSON.toJSONString(map), Medals.class);
        // 排序
        medalsService.reSort(medals);
        return super.edit(map);
    }

    /**
     * 删除信息
     *
     * @param id 主键
     * @return 结果
     */
    @Override
    public ResultObject delete(@PathVariable String id) {
        medalsService.reSort(id);
        return super.delete(id);
    }
}
